
// 判断参数是否是其中之一
export function oneOf(value, validList) {
    for (let i = 0; i < validList.length; i++) {
        if (value === validList[i]) {
            return true;
        }
    }
    return false;
}

export default function (IViewUI) {

    // 更改 formItem， 使 labelWidth 属性可以支持字符串。
    IViewUI.FormItem.props.labelWidth = { type: [String, Number] }
    // 修改左侧文字区域宽度
    IViewUI.FormItem.computed.labelStyles = function () {
        let style = {};
        const labelWidth = this.labelWidth === 0 || this.labelWidth ? this.labelWidth : this.FormInstance.labelWidth;
        if (typeof labelWidth == 'string') {
            style.width = `${labelWidth}`;
        } else if (labelWidth || labelWidth === 0) {
            style.width = `${labelWidth}px`;
        }
        return style;
    };
    // 修改右侧输入框区域左浮动
    IViewUI.FormItem.computed.contentStyles = function () {
        let style = {};
        const labelWidth = this.labelWidth === 0 || this.labelWidth ? this.labelWidth : this.FormInstance.labelWidth;
        if (typeof labelWidth == 'string') {
            style.marginLeft = `${labelWidth}`;
        } else if (labelWidth || labelWidth === 0) {
            style.marginLeft = `${labelWidth}px`;
        }
        return style;
    }
    IViewUI.Form.props.labelWidth = {
        type: [Number, String]
    };

}